package oktx.sample.dubbo;

import com.alibaba.dubbo.config.annotation.Reference;
import oktx.sample.dubbo.model.Book;
import oktx.sample.dubbo.model.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by dave on 18-5-20 上午11:20.
 */
@Service
@com.alibaba.dubbo.config.annotation.Service
public class ShopApiImpl implements ShopApi {
    @Autowired ShopMapper shopMapper;
    @Reference BookApi bookApi;

    @Override
    public Shop addShop(Shop shop) {
        shopMapper.insert(shop);
        return shop;
    }

    @Override
    public List<Shop> getShops() {
        return shopMapper.getList();
    }

    @Override
    public void removeAllShops() {
        shopMapper.clear();
    }

    @Override
    public Book restock(Book book, PostType type) {
        Book b = bookApi.addBook(book);
        if (type == PostType.rollbackByRemoteException) {
            throw new RuntimeException("WOW");
        }
        return b;
    }
}
